package tests;

import common.Utils;
import org.openqa.selenium.By;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 */
public class HomePage extends Utils {
    public static String url = "http://49.235.61.184/";

    public HomePage() {
        super(url);
    }
    //测试：检查页面元素
    public void checkHomePage() throws IOException, InterruptedException {

        //检查logo
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.nav-search.white.am-hide-sm-only > div > div.logo-big.theme-data-edit-event > a > img"));
        //检查搜索框
        driver.findElement(By.cssSelector("#search-input"));
        //检查“搜索”按钮
        driver.findElement(By.cssSelector("#ai-topsearch"));
        //检查“全部分类”
        driver.findElement(By.cssSelector("#goods-category > div > a > div > span"));
        //检查“首页”
        driver.findElement(By.cssSelector("#doc-topbar-collapse > ul > li:nth-child(1) > a"));
        //检查“运动健康”
        driver.findElement(By.cssSelector("#doc-topbar-collapse > ul > li:nth-child(2) > a"));
        //检查“汽车用品”
        driver.findElement(By.cssSelector("#doc-topbar-collapse > ul > li:nth-child(3) > a"));
        //检查“商品分类”
        driver.findElement(By.cssSelector("#doc-topbar-collapse > ul > li.am-dropdown > a"));
        //检查“个人中心”
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-center > div > a > span"));
        //检查“我的商城”
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-myself > div > a > span"));
        //检查“我的收藏”
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-favor > div > a > span"));
        //检查“更多入口”
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-quick > div > a > span"));
        //检查购物车
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-cart > div > a > span"));
        //检查“消息”
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-message > div > a > span"));
        //检查各类商品展示区域
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.home-floor"));
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());

        //搜索商品
        driver.findElement(By.cssSelector("#search-input")).sendKeys("手机");
        driver.findElement(By.cssSelector("#ai-topsearch")).click();
        String str1 = driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.breadcrumb-data.am-hide-sm-only > div > ul > li.am-active")).getText();
        //屏幕截屏
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        assert str1.equals("手机搜索结果");

        //点击”商城首页“按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-home > div > a")).click();

    }
    /**
     * 未登录状态的首页
     */
    public void notLoggedInHomePage() throws IOException, InterruptedException {
        //退出登录
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.slideall > div > div.mod-vip > div.m-baseinfo.am-flex.am-flex-items-center > div > a")).click();
        //检查“登录”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.slideall > div > div.mod-vip > div.member-login > a.am-btn-primary.btn.am-fl.am-radius"));
        //检查“注册”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.slideall > div > div.mod-vip > div.member-login > a.am-btn-warning.btn.am-fr.am-radius"));
        //屏幕截图
        Thread.sleep(1000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());

        //检查“个人中心”
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-center > div > a > span")).click();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //刷新
        driver.navigate().refresh();

        //检查“我的商城”
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-myself > div > a > span")).click();
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-myself > div > ul > li > a")).click();
        //屏幕截图
        Thread.sleep(1000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //刷新
        driver.navigate().refresh();

        //检查“我的收藏”
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-favor > div > a > span")).click();
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-favor > div > ul > li > a")).click();
        //屏幕截图
        Thread.sleep(1000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //刷新
        driver.navigate().refresh();

        //检查购物车
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-cart > div > a > span")).click();
        //屏幕截图
        Thread.sleep(1000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //刷新
        driver.navigate().refresh();

        //检查“登录”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.slideall > div > div.mod-vip > div.member-login > a.am-btn-primary.btn.am-fl.am-radius")).click();
        //屏幕截图
        Thread.sleep(1000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //后退
        driver.navigate().back();

        //检查“注册”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.slideall > div > div.mod-vip > div.member-login > a.am-btn-warning.btn.am-fr.am-radius")).click();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //后退
        driver.navigate().back();

    }

    /**
     * 登录状态的首页
     */
    public void homePageLogin() throws IOException, InterruptedException {
        //先登录
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.slideall > div > div.mod-vip > div.member-login > a.am-btn-primary.btn.am-fl.am-radius")).click();
        //清空输入框
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-g.user-login-container.am-padding-top-0.am-padding-bottom-0.theme-data-edit-event > div > div.am-container > div.am-u-sm-12.am-u-md-6.am-u-lg-4.user-right-container > div.am-radius-lg.am-background-white > div > div.am-tabs-bd.am-border-0 > div.am-tab-panel.am-active > form > div:nth-child(1) > input")).clear();
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-g.user-login-container.am-padding-top-0.am-padding-bottom-0.theme-data-edit-event > div > div.am-container > div.am-u-sm-12.am-u-md-6.am-u-lg-4.user-right-container > div.am-radius-lg.am-background-white > div > div.am-tabs-bd.am-border-0 > div.am-tab-panel.am-active > form > div:nth-child(2) > input")).clear();
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-g.user-login-container.am-padding-top-0.am-padding-bottom-0.theme-data-edit-event > div > div.am-container > div.am-u-sm-12.am-u-md-6.am-u-lg-4.user-right-container > div.am-radius-lg.am-background-white > div > div.am-tabs-bd.am-border-0 > div.am-tab-panel.am-active > form > div:nth-child(3) > input")).clear();
        Thread.sleep(3000);
        //输入登录账号
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-g.user-login-container.am-padding-top-0.am-padding-bottom-0.theme-data-edit-event > div > div.am-container > div.am-u-sm-12.am-u-md-6.am-u-lg-4.user-right-container > div.am-radius-lg.am-background-white > div > div.am-tabs-bd.am-border-0 > div.am-tab-panel.am-active > form > div:nth-child(1) > input")).sendKeys("linlin");
        //输入登录密码
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-g.user-login-container.am-padding-top-0.am-padding-bottom-0.theme-data-edit-event > div > div.am-container > div.am-u-sm-12.am-u-md-6.am-u-lg-4.user-right-container > div.am-radius-lg.am-background-white > div > div.am-tabs-bd.am-border-0 > div.am-tab-panel.am-active > form > div:nth-child(2) > input")).sendKeys("123456");
        //输入验证码 - 手动输入
        Thread.sleep(5000);
        //点击“登录“按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-g.user-login-container.am-padding-top-0.am-padding-bottom-0.theme-data-edit-event > div > div.am-container > div.am-u-sm-12.am-u-md-6.am-u-lg-4.user-right-container > div.am-radius-lg.am-background-white > div > div.am-tabs-bd.am-border-0 > div.am-tab-panel.am-active > form > div.am-form-group.am-form-group-refreshing.am-margin-top-lg.am-padding-0 > button")).click();
        Thread.sleep(3000);

        //检查“个人中心”
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-center > div > a > span")).click();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //后退
        driver.navigate().back();

        //检查“我的商城”
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-myself > div > a > span")).click();
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-myself > div > ul > li > a")).click();
        //屏幕截图
        Thread.sleep(1000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //后退
        driver.navigate().back();

        //检查“我的收藏”
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-favor > div > a > span")).click();
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-favor > div > ul > li > a")).click();
        //屏幕截图
        Thread.sleep(1000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //后退
        driver.navigate().back();

        //检查购物车
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-right > div.top-nav-items.top-nav-items-cart > div > a > span")).click();
        //屏幕截图
        Thread.sleep(1000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //后退
        driver.navigate().back();

        String str = driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.header-top > div > ul.top-nav-left.top-nav-left-content.am-hide-sm-only > div > div")).getText();
        assert str.equals("您好 linlin ，欢迎来到 网站名称 [退出]");

    }

}
